// 使用封装好的 axios （已设置默认选项）
import { type AxiosRequestConfig, type AxiosResponse } from 'axios'
import axiosInstance from './axios'
// 引入qs模块，用来序列化post类型的数据
// import QS from 'qs';
import { message } from 'ant-design-vue'

export interface RequestParams extends AxiosRequestConfig {
  data?: unknown
  params?: unknown
  message?: string
  allRes?: boolean
  mask?: boolean
}
export default {
  request: async (requestParams: RequestParams): Promise<any> => {
    try {
      return await new Promise((resolve, reject) => {
        axiosInstance(requestParams)
          .then((res: AxiosResponse) => {
            // console.log(res)
            resolve(res)
          })
          .catch((err) => { reject(err) })
          .finally(() => {
            // checkLoading(!!requestParams.mask)
          })
      })
    } catch (err) {
      // checkLoading(!!requestParams.mask)
      message.warning('出现错误，请稍后再试')
      return await Promise.reject(err)
    }
  }
}
